package com.example.mapper;



import com.example.bean.Borrow;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BorrowMapper {
    @Select("SELECT * FROM borrow WHERE userId=#{userId}")
    public List<Borrow> selectBorrowByUserId(int userId);    //查询某个用户借阅信息

    @Select("SELECT * FROM borrow WHERE userId=#{userId}")
    public Borrow selectBorrow(@Param("userId") int userId, @Param("bookId") String bookId);    //查询某个用户是否借阅某书

    @Select("SELECT * FROM borrow WHERE bookId=#{bookId}")
    public List<Borrow> selectBorrowById(String bookId);   //根据借阅信息Id查询借阅信息
    @Select("SELECT * FROM borrow")
    public List<Borrow> selectBorrowAll();    //查询所有借阅信息
    @Insert("INSERT INTO borrow(borrowId,userId,bookId,borrowTime,returnTime,fine,fineReason,userBorrowStatus) " +
            "VALUES(#{borrowId},#{userId},#{bookId},#{borrowTime},#{returnTime},#{fine},#{fineReason},#{userBorrowStatus})")
    public int insertBorrow(Borrow borrow);
    @Delete("DELETE FROM borrow WHERE borrowId=#{borrowId}")
    public int deleteBorrow(int borrowId);
    @Update("UPDATE borrow " +
            "SET bookId = #{bookId},userId=#{userId},borrowTime = #{borrowTime}, returnTime = #{returnTime}, fine = #{fine}," +
            "fineReason = #{fineReason}, userBorrowStatus = #{userBorrowStatus} " +
            "WHERE borrowId = #{borrowId}")
    public int updateBorrow(Borrow borrow);

}
